<?php


namespace app\api\controller\user;


use app\api\controller\Controller;
use app\api\model\UserBcard;
use app\api\service\Bank;
use app\common\exception\BaseException;

class Bcard extends Controller
{

    /* @var \app\api\model\User $user */
    private $user;

    /**
     * 构造方法
     * @throws \app\common\exception\BaseException
     * @throws \think\exception\DbException
     */
    public function _initialize()
    {
        parent::_initialize();
        $this->user = $this->getUser();   // 用户信息
    }

    /**
     * 修改结算银行卡
     */
    public function changecard(){
        $prama = $this->request->post();
        $prama['user_id'] = ($this->user)->user_id;
        $ubmodel = new UserBcard();
        if (!$ubmodel->changecard($prama)){
            return $this->renderError('银行卡数据修改失败:'.$ubmodel->getError());
        }else{
            return $this->renderSuccess(null,'银行卡修改成功!');
        }
    }

    /**
     * 获取用户绑定银行卡信息
     * @return array
     */
    public function details(){
        $ubmodel = new UserBcard();
        if (!$list = $ubmodel->getcards(($this->user)->user_id)){
            return $this->renderError('获取用户银行卡失败:'.$ubmodel->getError());
        }else{
            return $this->renderSuccess($list,'获取用户银行卡成功!');
        }
    }
}